package br.com.arosa.dao;

import java.util.*;
import java.sql.*;
import br.com.easynet.database.DataSet;
import br.com.jdragon.dao.*;
import br.com.arosa.transfer.*;

public class Tb_forma_pagamentoDAO extends ObjectDAO { 
	 public Tb_forma_pagamentoDAO(DAOFactory dao) throws Exception {
		 setDAOFactory(dao);
 		 con = dao.create();
 	 }

	 public void insert(Tb_forma_pagamentoT tb_forma_pagamentoT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "insert into tb_forma_pagamento  ( id_forma_pagamento, descricao) values ( ? , ? )";
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_forma_pagamentoT.getId_forma_pagamento());
			 pStmt.setObject(2, tb_forma_pagamentoT.getDescricao());
			 pStmt.execute();
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public void update(Tb_forma_pagamentoT tb_forma_pagamentoT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "update tb_forma_pagamento set  descricao=?  where  id_forma_pagamento=?";
 			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_forma_pagamentoT.getDescricao());
			 pStmt.setObject(2, tb_forma_pagamentoT.getId_forma_pagamento());
			 pStmt.execute();
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public void delete(Tb_forma_pagamentoT tb_forma_pagamentoT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "delete from tb_forma_pagamento where  id_forma_pagamento=?";
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_forma_pagamentoT.getId_forma_pagamento());
			 pStmt.execute();
		 } catch (Exception e)  {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 private List<Tb_forma_pagamentoT> resultSetToObjectTransfer(ResultSet rs) throws Exception { 
		 List<Tb_forma_pagamentoT> objs = new Vector();
		 while (rs.next()) { 
 			 Tb_forma_pagamentoT tb_forma_pagamentoT = new Tb_forma_pagamentoT();
			 tb_forma_pagamentoT.setId_forma_pagamento(rs.getInt("id_forma_pagamento"));
			 tb_forma_pagamentoT.setDescricao(rs.getString("descricao"));
			 objs.add(tb_forma_pagamentoT);
 		 }
 		 return objs; 
 	 }
	 public List<Tb_forma_pagamentoT> getAll() throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_forma_pagamento"; 
			 pStmt = con.prepareStatement(sql);
			 rs = pStmt.executeQuery();
 			 List<Tb_forma_pagamentoT> list = resultSetToObjectTransfer(rs);
 			 return list; 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_forma_pagamentoT> getById(Tb_forma_pagamentoT tb_forma_pagamentoT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_forma_pagamento where  id_forma_pagamento=?"; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_forma_pagamentoT.getId_forma_pagamento());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_forma_pagamentoT> getById_forma_pagamento(Tb_forma_pagamentoT tb_forma_pagamentoT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_forma_pagamento where  id_forma_pagamento = ? "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_forma_pagamentoT.getId_forma_pagamento());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_forma_pagamentoT> getByDescricao(Tb_forma_pagamentoT tb_forma_pagamentoT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_forma_pagamento where  Upper(descricao) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_forma_pagamentoT.getDescricao()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 

 }